package com.yhq.ojbackenduserservice.controller.inner;

import com.yhq.ojbackendmodel.model.vo.UserVO;
import com.yhq.ojbackendserviceclient.service.UserFeignClient;
import com.yhq.ojbackenduserservice.service.UserService;
import com.yhq.ojbackendmodel.model.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.List;

/**
 * @program: oj-backend-microservice
 * @description: 用户控制器（该服务仅供内部调用）
 * @author: HenryYang
 * @create: 2023-09-03 16:13
 **/
@RestController
@RequestMapping("/inner")
public class UserInnerController implements UserFeignClient {
    @Resource
    private UserService userService;

    /**
     * 根据用户id返回用户
     * @param userId
     * @return
     */
    @Override
    @GetMapping("/get/id")
    public User getById(@RequestParam("userId") long userId){
        return userService.getById(userId);
    }

    /**
     * 根据id获取用户列表
     * @param idList
     * @return
     */
    @Override
    @GetMapping("/get/ids")
    public List<User> listByIds(Collection<Long> idList) {
        return userService.listByIds(idList);
    }



//    @GetMapping("/get/ids")
//    @Override
//    public List<User> listByIds(@RequestParam("idList") Collection<Long> idList){
//        return userService.listByIds(idList);
//    }

    @Override
    public User getLoginUser(HttpServletRequest request) {
        return UserFeignClient.super.getLoginUser(request);
    }

    @Override
    public boolean isAdmin(User user) {
        return UserFeignClient.super.isAdmin(user);
    }

    @Override
    public UserVO getUserVO(User user) {
        return UserFeignClient.super.getUserVO(user);
    }
}